﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI;

namespace Acms.WebControls
{
    public class InfoPopUp : WebControl
    {
        public InfoPopUp()
        {
            Title = "Information";
        }

        public string Title { get; set; }
        public string Text { get; set; }

        protected override void Render(HtmlTextWriter writer)
        {
            if (!string.IsNullOrEmpty(Text))
            {

                writer.AddAttribute(HtmlTextWriterAttribute.Class, this.CssClass);

                writer.AddAttribute(HtmlTextWriterAttribute.Title, string.Concat(Title, !string.IsNullOrEmpty(Title) ? "*" : "", Text));
                if (!string.IsNullOrEmpty(ImageUrl))
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Src, Page.ResolveUrl(this.ImageUrl));
                    writer.RenderBeginTag(HtmlTextWriterTag.Img);
                    writer.RenderEndTag();
                }
                writer.RenderBeginTag(HtmlTextWriterTag.A);
                writer.RenderEndTag();
            }
        }

        protected override object SaveViewState()
        {
            ViewState["Text"] = Text;
            return base.SaveViewState();
        }

        protected override void LoadViewState(object savedState)
        {
            base.LoadViewState(savedState);
            Text = ViewState["Text"] as string;
        }

        public string ImageUrl { get; set; }
    }
}
